import pandas as pd
from pyecharts.charts import WordCloud
from pyecharts import options as opts

df = pd.read_excel('../data/20250527爱奇艺风云榜电影榜res.xlsx')

mainList = list(df['主演'].astype(str).map(lambda x: x.split(' ')))
mainActors = []
for i in mainList:
    for j in i:
        mainActors.append(j)

print(mainActors)
words_num = {}
for tag in mainActors:
    if tag not in words_num:
        words_num[tag] = 1
        continue
    words_num[tag] += 1


print(words_num)

# 绘制词云图
c = (
    WordCloud().add(
        # 系列名称，用于 tooltip 的显示，legend 的图例筛选。
        series_name="上榜电影数量",
        # 系列数据项，[(word1, count1), (word2, count2)]
        data_pair=words_num.items(),
        shape='triangle',
    )
        # 全局配置项
        .set_global_opts(
        # 标题设置
        title_opts=opts.TitleOpts(
            title='爱奇艺风云榜电影类主演上榜次数词云图',  # 标题
            # subtitle='数据来源：爱奇艺风云榜',
            # 设置标题样式
            title_textstyle_opts=opts.TextStyleOpts(
                font_size=25,
                width=1.5,
            ),
            pos_left='center',  # title位置
            pos_bottom='cenetr',
            pos_top='10',
        ),

        # 提示框设置
        tooltip_opts=opts.TooltipOpts(is_show=True),
    ).render("../pic/爱奇艺风云榜电影类主演上榜次数词云图.html")
)
